package model.loader;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Parser {
    private static Parser parser;

    public static final String COMMENT = "#";

    private Parser() {

    }
    /**
     * lazily instantiate our Parser
     *
     * @return current Parser instance or a brand new one if it is null
     */
    public static Parser getInstance() {
        if (parser == null) {
            parser = new Parser();
        }
        return parser;
    }

    public Scanner load(String filename) {
        return load(new File(filename));
    }
    
    public Scanner load(File file) {
        try {
            return new Scanner(file);
        } catch (FileNotFoundException e) {
            // TODO: better way to handle this exception
            e.printStackTrace();
            return null;
        }
    }

    /**
     * determines if the line currently being processed is a comment
     * @param line
     * @return
     */
    public static boolean isComment(String line) {
        return line.startsWith(COMMENT);
    }
}
